package LeetCode_1_100;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


class Solution01 {
    public int[] twoSum1(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int complement = target - nums[i];
            if (map.containsKey(complement)) {
                return new int[] { map.get(complement), i };
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No solution found");
    }
}
public class LeetCode01_twoSum {

    public static void main(String[] args) {
        Solution01 solution = new Solution01();
        int[] testNums1 = new int[] {2,7,11,15};
        int[] testNums2 = new int[] {3,2,4};
        int[] testNums3 = new int[] {3,3};
        int testTarget1 = 9;
        int testTarget2 = 6;
        int testTarget3 = 6;
        System.out.println(Arrays.toString(solution.twoSum1(testNums1,testTarget1)));
        System.out.println(Arrays.toString(solution.twoSum1(testNums2,testTarget2)));
        System.out.println(Arrays.toString(solution.twoSum1(testNums3,testTarget3)));
    }
}